export const table = {
  data: () => ({
    pickerOptions: {
      disabledDate(time) {
        return time.getTime() > Date.now();
      },
      shortcuts: [
        {
          text: "今天",
          onClick(picker) {
            picker.$emit("pick", new Date());
          },
        },
        {
          text: "昨天",
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit("pick", date);
          },
        },
        {
          text: "一周前",
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit("pick", date);
          },
        },
      ],
    },
    query: {
      currentPage: 0,
      pageSize: 0,
    },
    tableData: [],
    total: 0,
    goodsStatus: {
      0: "低库存",
      1: "损坏",
      2: "过期",
      3: "正常",
      4: "报废",
    },
    goodsWareHouse: {
      1: "防汛仓库",
      2: "备品备件仓库",
    },
    type: 4,
    typeOpt: [{ index: 4, value: "全部" }, { index: 0, value: "待提交" }, { index: 1, value: "待审核" }, { index: 2, value: "已通过" }, { index: 3, value: "未通过" }],
  }),
  async mounted() {
    console.log(2)
    const res1 = await this.$http.get(`/restful/v1/dd/permit/fillLoginUser?${Math.random()}`);
    const res2 = await this.$http.get(`/restful/v1/dd/permit/getUserDetail?${Math.random()}`);
    const isShow = res2.data.object.userRank
    localStorage.removeItem('isShow')
    localStorage.setItem('isShow', isShow)
    if (isShow === '2') {
      this.typeOpt = [{ index: 4, value: "全部" }, { index: 1, value: "待审核" }, { index: 2, value: "已通过" }, { index: 3, value: "未通过" }]
    }
    this.isShow = isShow
    var date = new Date()
    this.year = String(date.getFullYear())
    this.userInfo = res2.data.object
  },
  methods: {
    handleSizeChange(val) {
      this.fetch();
    },
    handleCurrentChange(val) {
      this.fetch();
    },
  },
  watch: {
    year () {
      this.fetch()
    },
    month () {
      if (this.month) {
        this.inboundTime = ''
      }
      this.fetch()
    }
  },
  computed: {
    newlist1 () {
      const length = this.tableData.length
      if (this.type !== 4) {
        var arr = []
        for (var i = 0; i < length; i++) {
          if (this.tableData[i].goodsStatus === this.type) {
            arr.push(this.tableData[i])
          }
        }
      } else {
        arr = this.tableData
      }
      this.total = arr.length
      return arr
    }
  }
}
